﻿/*
 * My Timer - cdGlobalClass.cs
 * 
 * Copyright (C) 2009 Ahmad Hanis Azmi
 * 
 * This file is part of My Timer
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;

namespace My_Timer
{
    //Class to create global forms value, quick and dirty solution
    public static class GlobalClass
    {
        //frmMain
        //Begin

        //Function to check if frmMain is created or not
        //Call before show frmMain
        public static void f_chkfrmMain()
        {
            if (r_frmMain.Created == false)
            {
                r_frmMain = new frmMain();
            }
        }
        public static frmMain r_frmMain = new frmMain();
        public static frmMain frmMain
        {
            get { return r_frmMain; }
            set { r_frmMain = value; }
        }

        //frmMain
        //END

        //frmAbout
        //Begin

        //Function to check if frmAbout is created or not
        //Call before show frmAbput
        public static void f_chkfrmAbout()
        {
            try
            {
                r_frmAbout.Dispose();
            }
            catch (Exception ex)
            {
#if DEBUG
                MessageBox.Show("Error caught in f_chkfrmAbout. Error: " + ex.Message);
#endif
            }
            if (r_frmAbout.Created == false)
            {
                r_frmAbout = new frmAbout();
            }
        }
        public static frmAbout r_frmAbout = new frmAbout();
        public static frmAbout frmAbout
        {
            get { return r_frmAbout; }
            set { r_frmAbout = value; }
        }

        //frmAbout
        //END

        //frmTimers
        //Begin

        //Function to check if frmTimers is created or not
        //Call before show frmTimers
        public static void f_chkfrmTimers()
        {
            if (r_frmTimers.Created == false)
            {
                r_frmTimers = new frmTimers();
            }
        }
        public static frmTimers r_frmTimers = new frmTimers();
        public static frmTimers frmTimers
        {
            get { return r_frmTimers; }
            set { r_frmTimers = value; }
        }

        //frmAbout
        //END

        //frmSettings
        public static frmSettings r_frmSettings;

        //status for frmTimers, add or edit
        public static string frmTimersStatus = "";

        //array location to add or edit timers
        public static int frmTimersStatusArrayLocation;

		//our Timers
        public static Dictionary<int, TimersArray> r_Timers = new Dictionary<int, TimersArray>();

        //timer control
        public static Dictionary<int, Timer> r_TimerControl = new Dictionary<int, Timer>();

        //Dialog result, store result from MessageBox so MessageBox is displayed only once
        public static Dictionary<int, DialogResult> drMessageBoxShowed = new Dictionary<int, DialogResult>();

        //Store result from MessageBox so MessageBox is displayed only once
        public static DialogResult dr_MessageBoxShowed = DialogResult.OK;

        //frmShutDown
        public static frmShutDown r_frmShutDown = null;

        // Next key for r_Timers
        public static int timerNextKey = 0;
    }

    public struct TimersArray
    {
        //START: Save to config
        //timer name
        public string Name;

        //On timer end, 0 = stop timer, 1 = restart timer
        public byte OnTimerEnd;

        //popup message box?
        public bool PopupMsgBox;
        public string MsgBoxString;

        //Play MP3 audio?
        public bool PlayAudio;
        public string PlayAudioPath;

        //0 = disabled, 1 = shutdown, 2 = restart
        public byte ShutdownComputer;

        //time
        public int Days;
        public int Hours;
        public int Minutes;
        public int Seconds;

        // frmTimersPopup possition
        public int xPossition;
        public int yPossition;

        // frmTimersPopup size
        public int xSize;
        public int ySize;

        // frmTimersPopup opacity
        public double form_Opacity;

        // frmTimersPopup always on top?
        public bool form_AlwaysOnTop;

        // open app or doc?
        public bool openApp;

        // app or doc location
        public string appLocation;

        // timer state
        // 0 = stopped/unactive
        // 1 = running
        // 2 = paused
        public byte timerState;

        //timer count down
        public int tDays;
        public int tHours;
        public int tMinutes;
        public int tSeconds;
        public int t_1_over_10_Seconds;

        //END: Save to config

        //timer key
        public int tKey;

        //timer enable/disable status, default is false
        public bool IsFormEnable;

        //form for timer
        public frmTimersPopup TimerForm;
        
        //timerControl for timer
        public Timer TimerControl;

        // lvTimers index
        public int iIndexOfKey;

        // is this timer deleted?
        public bool timerDeleted;
    }

    //My Timer settings
    public class Settings
    {
        public static bool StartMinimized;
    }
}